<?php
/* 
 * ********* CVS HEADER ********* 
 * 
 * $RCSfile: notification.php,v $ 
 * $Date: 2005/08/31 10:13:46 $ 
 * $Revision: 1.2 $ 
 * 
 * ********* CVS HEADER ********* 
 */
/**
  * Classe Notification
  * Developpee par Rodrigue LE GALL
  * sous licence GPL
  * Objectif : Envoyer des notifications avec des emails gerer par la 
  * classe EmailType
  */
require_once(get_path_module("email.emailtype"));

class Notification {
	var $_nom = '';
	var $_description = '';
	var $_emailID = 1;
	var $_ID = 0;
	function Notification($nom=''){
		$query = "SELECT * FROM rportal_notification WHERE nom='$nom'";
		$result=rportalrequete($query) or rportalerreur($query,"?op=");
		if(rportalnbresult($result)!=1){
		    return null;
		}
		$notif=rportalligne($result);
		$this->_nom = $notif['nom'];
		$this->_description = $notif['description'];
		$this->_emailID = $notif['id_email'];
		$this->_ID = $notif['id'];
	}
	
	function sendEmail($url){
		global $rportalparams;
		if($rportalparams->get_value("RPORTAL","email.actif")=="yes"){
			$email = new EmailType($this->_emailID);
			$email->setFrom($rportalparams->get_value("SITE","webmaster.nom"),$rportalparams->get_value("SITE","webmaster.email"));
			$email->setAutreX(0,$url);
			$query = "SELECT email FROM rportal_notification_abonnement WHERE nom_notification='".$this->_nom."'";
			$result=rportalrequete($query) or rportalerreur($query,"?op=");
			while($mel=rportalligne($result)){
				$email->setTo($mel['email'],'','','','');
				$email->sendEmail();
			}
		}
	}
	
	function abonnement($email){
		$query = "INSERT INTO rportal_notification_abonnement (nom_notification,email) VALUES ('".$this->_nom."','$email')";
		@rportalrequete($query) or rportalerreur($query,"?op=");
	}
	
	function desabonnement($email){
		$query = "DELETE FROM rportal_notification_abonnement WHERE nom_notification='".$this->_nom."' AND email='$email'";
		@rportalrequete($query) or rportalerreur($query,"?op=");
	}
}
?>